package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @InterfaceName: ShoppingCartMapper
 * @Author: YuanDing
 * @Date: 2024/2/6 17:38
 * @Description:
 */

@Mapper
public interface ShoppingCartMapper {


    /**
     * 根据条件查询购物车
     * @return
     */
    List<ShoppingCart> selectShoppingCart(ShoppingCartDTO shoppingCartDTO);


    /**
     * 更新购物车
     * @param shoppingCart
     */
    void updateShoppingCart(ShoppingCart shoppingCart);

    /**
     * 插入一条购物车数据
     * @param shoppingCart
     */
    void insertShoppingCart(ShoppingCart shoppingCart);

    /**
     * 查询用户id下的购物车列表
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> selectShoppingCartListByUserId(Long userId);

    /**
     * 根据菜品id和用户id查询购物车项
     * @param currentId
     * @param dishId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId} and dish_id = #{dishId}")
    ShoppingCart selectShoppingCartByUserIdAndDishId(Long userId, Long dishId);

    /**
     * 根据套餐id和用户id查询购物车项
     * @param currentId
     * @param dishId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId} and setmeal_id = #{setmealId}")
    ShoppingCart selectShoppingCartBysetmealIdAndDishId(Long userId, Long setmealId);

    /**
     * 根据id删除购物车项
     * @param id
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteShoppingCartById(Long id);

    /**
     * 清空购物车
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteAllByUserId(Long userId);
}
